//2018-05-06 00:15
//HQS
var eventforeshow_d = {};
var date=new Date;
var year=date.getFullYear(); 
var month=date.getMonth()+1;
$(function(){
	
	//PC端的部分样式
	
    
    //提示弹窗
    function toastDiv(toastHtml){
	   	$('.toastInfo span,.pop_up_prompts span').html(toastHtml);
	   	$('.toastInfo,.pop_up_prompts').fadeIn(1000).fadeOut(4000);
	}
    
    //以下代码为控制页面右侧 页面滚动出现“返回顶部”按钮
    var d_top = $('#com_d');
    $(document).scroll(function(){
        var scrTop = (document.body.scrollTop || document.documentElement.scrollTop);
        if (scrTop > 700){ d_top.show(); } else { d_top.hide(); }
    });
    $('#com_d').click(function() {
		$('html,body').animate({scrollTop: '0px'}, 500);
	});
    
    
    
    
    //moble/移动端部分js代码
   
	//所有游戏
	function AllGames(){
		//var neme = {"offset":0,"limit":4};
		$.ajax({
			type:"get",
			url:"/api/game/",
			async:true,
//			data:JSON.stringify(neme),
			//data:{"offset":0,"limit":4},   
			contentType:"application/json",
			dataType:"json",               
			success:function(res){
				if ( res.code == 0 ) {
					if ( res.data.length ) {
						$.each(res.data,function(i,item){
							if( i>3 ){ return false; }
							$(".AllGames .content").append('<a class="game"  href="game.html?game_id='+item["id"]+'">'+
															'<img src="'+item["icon"]+'"/>'+
															'<p>'+item["game_name"]+'</p>');
						});
                        if (res.data.length>4){
    						$(".AllGamesButton").removeClass("dis_none");
                            
                        }
					} else{
						//没有 游戏
						if (res.data.length == 0) {
							$(".AllGames .content").append('<p class="noGame">暂无游戏~</p>');
						}
						$(".AllGamesButton").addClass("dis_none");
					}

				} else{
					console.log(res.msg);
				}
			},error:function(res){
				console.log(res.message);
			}
		});
	}
	AllGames();
	
	
	//首页日历  轮播当前赛事   【开始】
	//获取完整的日期
    function acquisitionTime(){
    	window.date = new Date();
	    window.year = date.getFullYear();
	    window.month = date.getMonth() + 1;
	    window.strDate = date.getDate();
    }
    
    //获取现在时间
	function getNowFormatDate() {
		acquisitionTime();
	    window.d = new Date(year, (date.getMonth()+1), 0);
	    window.dataNum=d.getDate();
		bannerSwiper2(d.getDate());
		TheCurrentEvent(window.year,window.month); 
	    $(".Aleft").attr("data-month",month);//当前月份
	    $(".Aleft").attr("data-addUp",month);//当前跳转月份
	    $(".Aright").attr("data-month",month);//当前月份
	    $(".Aright").attr("data-addUp",month);//当前跳转月份
        if ( month == 1 ) {
        	Aleft = "去年十二月";
        	month = "一月";
        	Aright = "二月";
        } else if ( month == 2 ) {
        	Aleft = "一月";
        	month = "二月";
        	Aright = "三月";
        } else if ( month == 3 ) {
        	Aleft = "二月";
        	month = "三月";
        	Aright = "四月";
        } else if ( month == 4 ) {
        	Aleft = "三月";
        	month = "四月";
        	Aright = "五月";
        } else if ( month == 5 ) {
        	Aleft = "四月";
        	month = "五月";
        	Aright = "六月";
        } else if ( month == 6 ) {
        	Aleft = "五月";
        	month = "六月";
        	Aright = "七月";
        } else if ( month == 7 ) {
        	Aleft = "六月";
        	month = "七月";
        	Aright = "八月";
        } else if ( month == 8 ) {
        	Aleft = "七月";
        	month = "八月";
        	Aright = "九月";
        } else if ( month == 9 ) {
        	Aleft = "八月";
        	month = "九月";
        	Aright = "十月";
        } else if ( month == 10 ) {
        	Aleft = "九月";
        	month = "十月";
        	Aright = "十一月";
        } else if ( month == 11 ) {
        	Aleft = "十月";
        	month = "十一月";
        	Aright = "十二月";
        } else if ( month == 12 ) {
        	Aleft = "十一月";
        	month = "十二月";
        	Aright = "新年一月";
        }

	    $(".MONTH").text(month);
	    $(".Aleft").text(Aleft);
	    $(".Aright").text(Aright);
	}
	getNowFormatDate();
	
   	//当前赛事
	function TheCurrentEvent(year, month){
		eventforeshow_d= {};
		$.ajax({
			type:"get",
			url:"/api/eventforeshow/",
			async:false,
			data:{"offset":0,"limit":100,"year":year,"month":month},
			contentType:"application/json",
			dataType:"json",
			success:function(res){
				if ( res.code == 0 ) {
					$.each(res.datas,function(i,item){
						var _day = item.day;
						if (eventforeshow_d[_day]==undefined){
							eventforeshow_d[_day]=[item]
						}else{
							eventforeshow_d[_day].push(item)
						}
					});
				}
			},
		});
	}
    
	
    //当前赛事  月份选择 【左边】
	$(".Aleft").on("click",function(){
		acquisitionTime();
		strDate=1;
	    var i = parseInt($(this).attr("data-num"));
	    var val = parseInt($(this).attr("data-val"));
	    
		var dataMonth = parseInt($(this).attr("data-month"));//当前月份
		var addUp = parseInt($(this).attr("data-addUp"));//当前跳转月份
	    if ( (addUp-1) >= 1 ) {
	    	if ( (addUp-1) < (date.getMonth() + 1) ) {
	    		dd = new Date(year, (date.getMonth() + 1-val), 0);
		    	dataNum2=dd.getDate();
			    $(this).attr("data-val",val+1);
		    	$(".Aright").attr("data-val",val+1);
	    	}else if( (addUp-1) == (date.getMonth() + 1) ){
	    		dd = new Date(year, (date.getMonth() + 1), 0);
		    	dataNum2=dd.getDate();
		    	$(this).attr("data-val","1");
		    	$(".Aright").attr("data-val","1");
	    	}else{
	    		dd = new Date(year, (date.getMonth() + 1+(val-2)), 0);
		    	dataNum2=dd.getDate();
		    	$(this).attr("data-val",val-1);
		    	$(".Aright").attr("data-val",val-1);
	    	}
		    	
		    html="";
		    $("#bannerSwiper2 .swiper-wrapper").html(html);
		    bannerSwiper2(dd.getDate());
		    pClass();
			EventList();
		    $(this).attr("data-num",i+1);
		    
		    $(".Aleft,.Aright").attr("data-addUp",addUp-1);
		    mySwiper.slideTo(0, 1000, false);
	    }else{
	    	return false;
	    }

		var thisText = $(this).text();
		if( thisText == "一月" ){
			$(this).text("去年");
			$(".MONTH").text("一月");
			$(".Aright").text("二月");
		} else if( thisText == "二月" ){
			$(this).text("一月");
			$(".MONTH").text("二月");
			$(".Aright").text("三月");
		} else if( thisText == "三月" ){
			$(this).text("二月");
			$(".MONTH").text("三月");
			$(".Aright").text("四月");
		} else if( thisText == "四月" ){
			$(this).text("三月");
			$(".MONTH").text("四月");
			$(".Aright").text("五月");
		} else if( thisText == "五月" ){
			$(this).text("四月");
			$(".MONTH").text("五月");
			$(".Aright").text("六月");
		} else if( thisText == "六月" ){
			$(this).text("五月");
			$(".MONTH").text("六月");
			$(".Aright").text("七月");
		} else if( thisText == "七月" ){
			$(this).text("六月");
			$(".MONTH").text("七月");
			$(".Aright").text("八月");
		} else if( thisText == "八月" ){
			$(this).text("七月");
			$(".MONTH").text("八月");
			$(".Aright").text("九月");
		} else if( thisText == "九月" ){
			$(this).text("八月");
			$(".MONTH").text("九月");
			$(".Aright").text("十月");
		} else if( thisText == "十月" ){
			$(this).text("九月");
			$(".MONTH").text("十月");
			$(".Aright").text("十一月");
		} else if( thisText == "十一月" ){
			$(this).text("十月");
			$(".MONTH").text("十一月");
			$(".Aright").text("十二月");
		}
	});
	
	//当前赛事  月份选择 【右边】
	$(".Aright").on("click",function(){
		acquisitionTime();
	    var i = parseInt($(this).attr("data-num"));
	    var val = parseInt($(this).attr("data-val"));
	    
		var dataMonth = parseInt($(this).attr("data-month"));//当前月份
		var addUp = parseInt($(this).attr("data-addUp"));//当前跳转月份

	    if ( (addUp+1) <= 12 ) {
	    	if ( (addUp+1) > (date.getMonth() + 1) ) {
	    		dd = new Date(year, (date.getMonth() + 1+val), 0);
		    	dataNum2=dd.getDate();
			    $(this).attr("data-val",val+1);
			    $(".Aleft").attr("data-val",val+1);
			    
		    	console.log((date.getMonth() + 1+val)+"月份");
			    console.log(dataNum2+"个日子");
	    	}else if( (addUp+1) == (date.getMonth() + 1) ){
	    		dd = new Date(year, (date.getMonth() + 1), 0);
		    	dataNum2=dd.getDate();
		    	$(this).attr("data-val","1");
		    	$(".Aright").attr("data-val","1");
	    	} else{
	    		dd = new Date(year, (date.getMonth() + 1-(val-2)), 0);
		    	dataNum2=dd.getDate();
			    $(this).attr("data-val",val-1);
			    $(".Aleft").attr("data-val",val-1);
	    	}
		    	
		    html="";
		    $("#bannerSwiper2 .swiper-wrapper").html(html);
		    bannerSwiper2(dd.getDate());
		    pClass();
			EventList();
		    $(this).attr("data-num",i+1);
		    $(".Aleft,.Aright").attr("data-addUp",addUp+1);
		    mySwiper.slideTo(0, 1000, false);
	    }else{
	    	return false;
	    }
		
		var thisText = $(this).text();
		
		if( thisText == "二月" ){
			$(".Aleft").text("一月");
			$(".MONTH").text("二月");
			$(this).text("三月");
		} else if( thisText == "三月" ){
			$(".Aleft").text("二月");
			$(".MONTH").text("三月");
			$(this).text("四月");
		} else if( thisText == "四月" ){
			$(".Aleft").text("三月");
			$(".MONTH").text("四月");
			$(this).text("五月");
		} else if( thisText == "五月" ){
			$(".Aleft").text("四月");
			$(".MONTH").text("五月");
			$(this).text("六月");
		} else if( thisText == "六月" ){
			$(".Aleft").text("五月");
			$(".MONTH").text("六月");
			$(this).text("七月");
		} else if( thisText == "七月" ){
			$(".Aleft").text("六月");
			$(".MONTH").text("七月");
			$(this).text("八月");
		} else if( thisText == "八月" ){
			$(".Aleft").text("七月");
			$(".MONTH").text("八月");
			$(this).text("九月");
		} else if( thisText == "九月" ){
			$(".Aleft").text("八月");
			$(".MONTH").text("九月");
			$(this).text("十月");
		} else if( thisText == "十月" ){
			$(".Aleft").text("九月");
			$(".MONTH").text("十月");
			$(this).text("十一月");
		} else if( thisText == "十一月" ){
			$(".Aleft").text("十月");
			$(".MONTH").text("十一月");
			$(this).text("十二月");
		} else if( thisText == "十二月" ){
			$(".Aleft").text("十一月");
			$(".MONTH").text("十二月");
			$(this).text("新年");
			return false;
		}
	});
	
	
	//循环每月的日子
	function bannerSwiper2(dataNum){
		var html="",playArea="";
		for(var QQ=1; QQ<=dataNum; QQ++ ){
			html += '<div class="swiper-slide"><a href="javascript:;">'+QQ+'</a></div>';
			pClass(dataNum);
			arrangement(dataNum);
		}
		$("#bannerSwiper2 .swiper-wrapper").append(html);
	}
	bannerSwiper2();
	
	
	//那天有的游戏  即  那天的赛事 的游戏名称
	function pClass(activeIndex){
		var html="",playArea="";
		if (eventforeshow_d[activeIndex]!==undefined){
			var _data  = eventforeshow_d[activeIndex][0];
			playArea = _data.game_name;
			$(".pullDown").removeClass("dis_none");
			$(".pullDown").attr("data-switch","0");
			$(".imgClass1").attr("src",_data.icon);
			$(".imgClass1,.spanClass").css({opacity:"1",height:"2rem"});
			$("#pClass").attr("data-val",_data.game_id);
		}else{
			$(".pullDown,.EventList").addClass("dis_none");
			$(".pullDown").attr("data-switch","3");
			$(".imgClass1").attr("src","");
			$(".imgClass1,.spanClass").css({opacity:"0",height:"0"});
		}
		$("#pClass").text(playArea);
	}
	
	//循环当前赛事当天包含的【所有】游戏列表
	function EventList(activeIndex){
		var html1="",html2="";
		var arr  = new Array()
		if (eventforeshow_d[activeIndex]!=undefined){
			$.each(eventforeshow_d[activeIndex],function(i,item){
				var game_id = item.game_id;
				if (arr.indexOf(game_id)==-1){
					arr.push(game_id);
					html1 += '<a class="option" href="javascript:;" data-val="'+game_id+'">'+
								'<img class="imgClass" src="'+item.icon+'"/>'+
								'<p class="pClass apostrophe">'+item.game_name+'</p>'+
							'</a>';
				}
			});
		}
		$(".calendar_bottom .EventList").html(html1);
		optionSelect(activeIndex);
	}
	//EventList(strDate);

	//查找当前赛事 其中一种游戏的赛事情况
	function arrangement(activeIndex){
		var DeviceWidth = $(window).width();//监听当前设备 的宽度，防止错位
		var _game_id = $("#pClass").attr("data-val");
		var html="",colour="",bgCondition="",official="",state="";
		if( DeviceWidth<= 320 ){
			gameTime='<p class="gameTime">比赛时间：<br />16：00-18：00</p>';
		}else{
			gameTime='<p class="gameTime">比赛时间：16：00-18：00</p>';
		}
		if (eventforeshow_d[activeIndex]!==undefined) {
			$.each(eventforeshow_d[activeIndex],function(i,item){
				if (parseInt(item.game_id)==parseInt(_game_id)){
                    var status = item['status']
                    var status_class = 'status_underway'
                    var isvideo = '直播'
                    if (status=='等待开赛') {
                    	colour="fontColor1";
                    	bgCondition="bgCondition1";
                    	bgGameSort="bgGameSort3";
						official="官方";
                        isvideo = '敬请期待'
                    }else if(status =='比赛中'){
                    	colour="fontColor2";
                    	bgCondition="bgCondition2";
                    	bgGameSort="bgGameSort2";
                    	official="平台";
                        isvideo = '直播'
                    }else{
                    	colour="fontColor3";
                    	bgCondition="bgCondition3";
                    	bgGameSort="bgGameSort1";
                    	official="业余";
                        isvideo ='集锦'
                        status_class = 'status_complete'
                    }

					html += '<a class="main fix" href="competition.html?event_id='+item['event_id']+'">'+
								'<img class="GamePreview" src="'+item['event_icon']+'"/>'+
								'<div class="description">'+
			                    	'<p class="apostrophe">'+item['events_title']+'</p>'+
			                    	gameTime+
			                    	'<p class="gameSort '+bgGameSort+'">'+item['event_type_name']+'</p>'+
			                    '</div>'+
			                    '<div class="status">'+
				                    '<p class="'+colour+'"><span class="'+bgCondition+'"></span>'+status+'</p>'+
				                    '<button type="button"><img src="http://pd51ux91p.bkt.clouddn.com/index/icon_play.png"/> '+isvideo+'</button>'+
			                    '</div>'+
			                '</a>';				
				}
			});
		}
		if (html==""){
			NoCompetitiontoday();
		}
		$("#arrangement").html(html);
	}
	
	//循环 无赛事
	function NoCompetitiontoday(){
		$(".pullDown").attr("data-switch","3").removeClass("dis_none");
		$(".imgClass1").attr("src","");
		$(".imgClass1,.spanClass").css({opacity:"0",height:"0"});
		$("#arrangement").html('<p align="center" class="notHave">暂无赛事情况喔~</p>');

	}
	
	//首页 当前赛事  日历
	var mySwiper = new Swiper('#bannerSwiper2',{
			slidesPerView : 7,//设置slider容器能够同时显示的slides数量(carousel模式)
	        autoplayDisableOnInteraction : false,
	        initialSlide:(strDate-1),//用来设定页面加载完成时，第几张图片先显示出来
    		centeredSlides: true,
    		observer:true,
    		onSlideChangeStart: function(swiper){ //回调函数，swiper从一个slide过渡到另一个slide结束时执行
    			pClass(swiper.activeIndex);  //当发生  滚动日历的操作，就自动循环当天的第一个游戏是否存在
				EventList(swiper.activeIndex); //循环当前赛事当天包含的游戏【所有】
    			arrangement(swiper.activeIndex); //循环  当前赛事 的其中一种游戏的赛事情况
    			optionSelect(swiper.activeIndex);
    		}
	});

	//当前赛事  选择游戏  下拉列表
	$(".pullDown").on("click",function(){
		var lengthNum = $(this).next(".EventList").children("a").length;
		var dataSwitch = $(this).attr("data-switch");
		if ($(".EventList").attr("class") == "EventList dis_none" && dataSwitch == 0 ) {
			$(".EventList").removeClass("dis_none");
			$(".EventList").css("height",lengthNum*2+"rem");
			$(".pullDown").attr("data-switch","1");
			$(".spanClass").css("background-image","url(http://pd51ux91p.bkt.clouddn.com/index/calendar_pullUp.png)");
		}else if($(".EventList").attr("class") == "EventList" && dataSwitch == 1 ){
			$(".EventList").addClass("dis_none");
			$(".EventList").css("height","0rem");
			$(".pullDown").attr("data-switch","0");
			$(".spanClass").css("background-image","url(http://pd51ux91p.bkt.clouddn.com/index/calendar_pullDown.png)");
		}
	});
	
	//当前赛事 在游戏列表  选择其中一款 游戏
	function optionSelect(activeIndex){
		$(".option").on("click",function(){
			if ($(".EventList").attr("class") == "EventList" ) {
				$(".pullDown").children("img").attr("src",$(this).children("img").attr("src"));
				$(".pullDown").children("p").text($(this).children("p").text());
				$("#pClass").attr("data-val",$(this).attr("data-val"));
				$(".EventList").css("height","0rem");
				$(".EventList").addClass("dis_none");
				$(".pullDown").attr("data-switch","0");
				$(".spanClass").css("background-image","url(http://pd51ux91p.bkt.clouddn.com/index/calendar_pullDown.png)");
				arrangement(activeIndex); //参数为当前的日期
			}
		});
	}
	//首页日历  轮播当前赛事   【结束】
	
	
	
	
	//热门赛事
	function PopularEvents(){
		$.ajax({
			type:"get",
			url:"/api/tournament/",
			async:true,
			data:{"hot_status":1,"limit":3},
			contentType:"application/json",
			dataType:"json",
			success:function(res){
				if ( res.code == 0 ) {
					$.each(res.datas,function(i,item){
						
						var _type=1
						var type = item.type
						if (type==3 || type ==4){
							_type =2
						}else if (type ==5){
							_type = 3
						}
                        var html = '<div class="events shadow2 fix">'+
                                '<a class="fix" href="competition.html?event_id='+item.id+'">'+
                                '<p class="description apostrophe"><img src="'+item['icon']+'"/>'+item['events_title']+'</p>'+
                                '<p class="money apostrophe"><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_PopularEvents1.png"/>'+item['total_bonus']+'</p>'+
                                '<p class="time"><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_PopularEvents2.png"/>'+item['apply_start_time']+'报名开始</p>'+
                                '<p class="number"><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_PopularEvents3.png"/>'+item['has_team']+'/'+item['max_team']+'</p>'+
                                '<p class="condition"><span class="bgCondition'+_type+'"></span>'+item['status']+'</p>'+
                                '<p class="category bgColor1"><span>'+item['event_type_name']+'</span></p>'+
                                '</a>'+
                                '</div>'
						$(".PopularEvents .content").append(html);
					});
				} else{
					console.log(res.msg);
				}
			},error:function(res){
				console.log(res.message);
			}
		});
	}
	PopularEvents();


    function  Img(img_list){
        var image = '';
        $.each(img_list,function(i,item){
            image += '<img src="'+item+'"/>'
        });
        return image
    }
    
     //排行榜 信息 切换
    $(".Crunchies").on("click",function(){
    	if ( $(this).index() == 0 ) {
    		$(this).addClass("avter");
    		$(this).siblings().removeClass("avter");
    		$(".TeamLIst").removeClass("dis_none");
    		$(".EventsLIst").addClass("dis_none");
    	} else{
    		$(this).addClass("avter");
    		$(this).siblings().removeClass("avter");
    		$(".EventsLIst").removeClass("dis_none");
    		$(".TeamLIst").addClass("dis_none");
    	}
	});
	
    //排行榜  战队榜
    function  TeamEvent(){
        $.ajax({
            type:"get",
            url:"/api/teamperformance/",
            async:true,
            data:{"performance_type":"all","limit":10},
            contentType:"application/json",
            dataType:"json",
            success:function(res){
                if ( res.code == 0 ) {
                    var html = '';
                    var rank = 0;
                    $.each(res.datas,function(i,item){
                        rank = item.rank
                        if (item.rank ==1){
                            html += '<div class="CrunchiesChampion">'
                            html += '<div class="position position_one"><a href="edg_website.html?team_id='+item.id+'"><div class="Chemistry"><img src="'+item.team_icon+'"/>'
                            html += '<p class="TeamName"><i class="apostrophe">'+item.team_name+'</i></p><span class="CrunchiesBG CrunchiesBG1"></span><span class="num">'+rank+'</span></div>'
                            html += '<div class="include"><div class="game">'+Img(item.game_icon_urls)+'</div><p><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_medal.png"/> '+item.competition_point+'</p></div></a></div>'
                        }else if (item.rank==2){
                            html +='<div class="position position_two"><a href="edg_website.html?team_id='+item.id+'">'+
                            '<div class="Chemistry">'+
                                '<img src="'+item.team_icon+'"/>'+
                                '<p class="TeamName"><i class="apostrophe">'+item.team_name+'</i></p>'+
                                '<span class="CrunchiesBG CrunchiesBG2"></span>'+
                                '<span class="num">'+rank+'</span>'+
                            '</div>'+
                            '<div class="include">'+
                            '<div class="game">'
                            +Img(item.game_icon_urls)+'</div><p><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_medal.png"/> '+item.competition_point+'</p></div></a></div>'
                        }else if(item.rank==3){
                            html  +='<div class="position position_three"><a href="edg_website.html?team_id='+item.id+'">'+
                                        '<div class="Chemistry">'+
                                            '<img src="'+item.team_icon+'"/>'+
                                            '<p class="TeamName"><i class="apostrophe">'+item.team_name+'</i></p>'+
                                            '<span class="CrunchiesBG CrunchiesBG3"></span>'+
                                            '<span class="num">'+rank+'</span>'+
                                        '</div>'+
                                        '<div class="include">'+
                                            '<div class="game">'+
                                            Img(item.game_icon_urls)+
                                            '</div>'+
                                            '<p><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_medal.png"/> '+item.competition_point+'</p>'+
                                        '</div>'+
                                    '</a></div>'+
                                '</div><div class="CrunchiesRanking fix">'
                        }else{
                            html +='<div class="list"><a href="edg_website.html?team_id='+item.id+'">'+
                                        '<span class="ranking">'+rank+'</span>'+
                                        '<span class="teamLogo"><img src="'+item.team_icon+'"/></span>'+
                                        '<span class="TeamName apostrophe">'+item.team_name+'</span>'+
                                        '<span class="correlationGame">'+
                                        Img(item.game_icon_urls)+
                                        '</span>'+
                                        '<span class="combatGains"><img src="http://pd51ux91p.bkt.clouddn.com/public/icon_medal.png"/>'+item.competition_point+'</span>'+
                                    '</a></div>'


                        }
                    });

                    if (rank < res.total){
                        html  +='<a class="viewMore viewMore1" href="edg.html">查看更多</a>'
                    }
                    if (res.datas.length==0) {
                    	html ='<p class="noGame">暂时还没有战队上榜~</p>'
                    }
                    
                    $(".rankingList .TeamLIst").append(html);
                } else{
                    console.log(res.msg);
                }
            },error:function(res){
                console.log(res.message);
            }
        });


    }
    TeamEvent();
    //排行榜  赛事榜
    function EventRank(offset, limit){
        $.ajax({
            type:"get",
            url:"/api/eventperformance/",
            async:true,
            data:{"offset":offset,"limit":limit},
            contentType:"application/json",
            dataType:"json",
            success:function(res){
                if ( res.code == 0 ) {
                    var html  = '';
                    $.each(res.datas,function(i,item){
                        var fontColor = ''
                        var bgCondition = ''
                        var event_status = item.event_status
                        if(event_status.indexOf('比赛中') > -1){
                            fontColor = 'fontColor2'
                            bgCondition = 'bgCondition2'
                        }else if (event_status.indexOf('报名中')>-1){
                            fontColor = 'fontColor1'
                            bgCondition = 'bgCondition1'                           
                        }else if (event_status.indexOf('天后开放报名')>-1){
                            fontColor = 'fontColor1'
                            bgCondition = 'bgCondition1'  
                            event_status = '预报名'
                        }else if ( event_status.indexOf('等待开赛')>-1){
                            fontColor = 'fontColor2'
                            bgCondition = 'bgCondition2'                              
                        }

                        else if (event_status.indexOf('比赛结束')>-1) {
                            fontColor = 'fontColor3'
                            bgCondition = 'bgCondition3' 
                            event_status = '已结束'
                            
                        }
                        html +='<a href="competition.html?event_id='+item.id+'"><div class="list">'+
                                    '<span class="TeamName apostrophe">'+item.event_title+'</span>'+
                                    '<span class="sort">'+item.event_type_name+'</span>'+
                                    '<span class="bonus">￥'+item.total_bonus+'</span>'+
                                    '<span class="status '+fontColor+'">'+event_status+'</span>'+
                                    '<span class="statusMap"><i class="'+bgCondition+'"></i></span>'+
                                '</div></a>'
                    });
                    if (html ==''){
                        html = '<p class="noGame">暂无赛事榜信息~</p>'
                    }
                    $(".EventsLIst .CrunchiesRanking").append(html);
                } else{
                    console.log(res.msg);
                }
            },error:function(res){
                console.log(res.message);
            }
        });       
    }
    EventRank(0,10)

    if (getCookie("token")=='null') {
        setCookie('token',getUrlParms('token'))
    }
    if(getCookie('user_id')=='null'){
        setCookie("user_id",getUrlParms('user_id'))
    }
	
	
	//首页  底部 排行榜 根据  冠亚季军的 相关 游戏数量  小图标 自动添加样式
	var numLength1 = $(".position_one .location").children().length;
	var numLength2 = $(".position_two .location").children().length;
	var numLength3 = $(".position_three .location").children().length;
	window.onload=function(){
		if ( numLength1 == 1 ) {
			$(".position_one .location").children().eq(0).css("margin-left","45%");
		} else if ( numLength1 == 2 ) {
			$(".position_one .location").children().eq(0).css("margin-left","30%");
		} else{
			$(".position_one .location").children().eq(0).css("margin-left","15%");
		}
		if ( numLength2 == 1 ) {
			$(".position_two .location").children().eq(0).css("margin-left","45%");
		} else if ( numLength2 == 2 ) {
			$(".position_two .location").children().eq(0).css("margin-left","30%");
		} else{
			$(".position_two .location").children().eq(0).css("margin-left","15%");
		}
		if ( numLength3 == 1 ) {
			$(".position_three .location").children().eq(0).css("margin-left","45%");
		} else if ( numLength3 == 2 ) {
			$(".position_three .location").children().eq(0).css("margin-left","30%");
		} else{
			$(".position_three .location").children().eq(0).css("margin-left","15%");
		}
	}

	$("#navButtonAttention").on("click",function(){
        $.ajax({
            type:"post",
            url:"/api/focusonwe/",
            async:true,
            data:JSON.stringify({"user_id":getCookie("yz_id"),"token":getCookie("yz_tk")}),
            contentType:"application/json",
            dataType:"json",
            success:function(res){
                layer.msg(res.msg)
            },error:function(res){
                layer.msg("出错了~")
            }
        }); 
	})
});
